/**
 * Project hdmap
 * @author shengjialiang
 * @version v1.0
 */


#include "map_datarender/IRenderObject.h"
#include "map_common/CoorSystem.h"

/**
 * IRenderObject implementation
 */

namespace DataRender
{
    CRenderNode::CRenderNode()
        : Owner(NULL)
    {

    }

    CRenderNode::~CRenderNode()
    {

    }

    IRenderObject::IRenderObject(osg::ref_ptr<osg::Group> in_pParentNode)
        : mpRefFeature(NULL), mpRefParentNode(in_pParentNode), mpRefOwner(NULL), mCanSelect(true)
        , mBox(osg::BoundingBox(osg::Vec3f(0, 0, 0), osg::Vec3f(0, 0, 0))), mRenderType(""),
		mMatrix(osg::Matrix::identity()), mAdjustmatrix(osg::Matrix::identity()), mVisible(true), mVisibleDistance(200)
    {

    }

    IRenderObject::~IRenderObject()
    {

    }

    osg::ref_ptr<osg::Group> IRenderObject::getParentNode()
    {
        return this->mpRefParentNode;
    }

    osg::ref_ptr<CRenderNode> IRenderObject::getRenderNode()
    {
        return this->mpRenderNode;
    }

    void IRenderObject::setFeature(DataManager::IFeature* in_pFeature)
    {
        this->mpRefFeature = in_pFeature;
    }

    DataManager::IFeature* IRenderObject::getFeature()
    {
        return this->mpRefFeature;
    }

	void IRenderObject::setOwner(Common::CObject* in_pRefOwner)
    {
        this->mpRefOwner = in_pRefOwner;
    }

	Common::CObject* IRenderObject::getOwner()
    {
        return this->mpRefOwner;
    }

    osg::Matrix IRenderObject::getMatrix()
    {
        return mMatrix;
    }

    void IRenderObject::setMatrix(const osg::Matrix& in_matrix)
    {
        this->mMatrix = in_matrix;
    }

    osg::Matrix IRenderObject::getAdjustMatrix()
    {
        return this->mAdjustmatrix;
    }

    void IRenderObject::setAdjustMatrix(const osg::Matrix& in_adjustmatrix)
    {
        this->mAdjustmatrix = in_adjustmatrix;
    }

    void IRenderObject::setVisible(const bool& in_visible)
    {
        this->mVisible = in_visible;
    }

    bool IRenderObject::getVibible()
    {
        return this->mVisible;
    }

	void IRenderObject::setVisibleDistance(const double& in_visibleDistance)
	{
		this->mVisibleDistance = in_visibleDistance;
	}
	double IRenderObject::getVisibleDistance()
	{
		return this->mVisibleDistance;
	}

    bool& IRenderObject::getCanSelect()
    {
        return this->mCanSelect;
    }

    osg::BoundingBox& IRenderObject::getBox()
    {
        if (this->getFeature()
            && this->mBox.center() == osg::Vec3d(0,0,0))
        {
            osg::Vec3d max = this->getFeature()->getExtendMax();
            osg::Vec3d min = this->getFeature()->getExtendMin();

            max -= Common::CCoorSystem::instance()->getReferenceCenter();
            min -= Common::CCoorSystem::instance()->getReferenceCenter();
            osg::BoundingBox bb(min,max);
            this->mBox = bb;
        }
        return this->mBox;
    }

    std::string IRenderObject::getRenderType()
    {
        return this->mRenderType;
    }

    void IRenderObject::setRenderType(const std::string& in_renderType)
    {
        this->mRenderType = in_renderType;
    }

    bool IRenderObject::canRender(osg::Node* node, osg::NodeVisitor* nv, osgViewer::Viewer* viewer)
    {
        bool r = false;

        return r;
    }

    void IRenderObject::lock()
    {
        this->mRenderMutex.lock();
    }

    void IRenderObject::unlock()
    {
        this->mRenderMutex.unlock();
    }
}